﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
using mvcDemo.Models;

namespace mvcDemo.Controllers
{
    public class remarksController : ApiController
    {
        // GET api/remarks
        /// <summary>
        /// 获取所有评语
        /// </summary>
        /// <returns></returns>
        public JsonMessage Get()
        {
            try
            {
                using (Entities db = new Entities())
                {
                    List<REMARK> remarks = db.REMARK.ToList();
                    return new JsonMessage(remarks);
                }
            }
            catch (Exception ex)
            {
                return new JsonMessage("获取评语失败！", ex.Message, ex.StackTrace);
            }
        }

        // GET api/remarks/5
        /// <summary>
        /// 获取指定评语
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public JsonMessage Get(int id)
        {
            try
            {
                using (Entities db = new Entities())
                {
                    REMARK remark = db.REMARK.Find(id);
                    return new JsonMessage(remark);
                }
            }
            catch (Exception ex)
            {                
                return new JsonMessage("获取评语失败！", ex.Message, ex.StackTrace);
            }
        }
       
    }
}
